package com.ian.controller;

import com.common.util.ResultMsg;
import com.ian.pojo.PerArticle;
import com.ian.service.PerArticleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 新闻
 *
 * @Author IanZy
 * @Date 2020/6/20
 */
@Api("新闻相关的API")
@RestController
public class PerArticleController {
    @Autowired
    PerArticleService perArticleService;

    /**
     * 获取新闻列表
     *
     * @Author IanZy
     * @Date 2020/6/20
     */
    @ApiOperation("获取新闻列表")
    @GetMapping(value = "/articles", produces = "application/json;charset=UTF-8")
    public ResultMsg findAllArticles(@RequestParam("mobile") String mobile) {
        if (mobile != null) {
            List<PerArticle> articleList = perArticleService.findAllArticles();
            return ResultMsg.success("查询新闻列表成功~", articleList);
        }
        return ResultMsg.failed("查询新闻列表失败~");
    }

    /**
     * 根据id跳转对应新闻详情页
     *
     * @Author IanZy
     * @Date 2020/6/20
     */
    @ApiOperation("查询新闻详情")
    @GetMapping(value = "/detail", produces = "application/json;charset=UTF-8")
    public ResultMsg detail(@RequestParam("id") int id) {
        if (id != 0) {
            PerArticle perArticle = perArticleService.selectByPrimaryKey(id);
            return ResultMsg.success("查询新闻详情成功~", perArticle);
        }
        return ResultMsg.failed("查询新闻详情失败~");
    }
}
